/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.taglib;

import com.minierp.bean.TreeObjectInterface;
import java.util.List;
import java.util.Stack;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class CreateSelectTree extends TagSupport {
	private static final long serialVersionUID = 1L;
	private List list;
	private String exceptCode;
	private int emptyOption = 1;
	private String defaultValue;
	private int justEnabled = 0;

	public int getJustEnabled() {
		return this.justEnabled;
	}

	public void setJustEnabled(int justEnabled) {
		this.justEnabled = justEnabled;
	}

	public int doStartTag() throws JspException {
		try {
			JspWriter e = this.pageContext.getOut();
			String str = "";
			if (this.emptyOption == 1) {
				str = "<option value=\'\'></option>";
			}

			Stack stack = new Stack();
			Stack layerNumStack = new Stack();
			String defParentStr = "";
			TreeObjectInterface obj;
			int nextParentCode;
			if (this.defaultValue != null && !this.defaultValue.equals("")
					&& !this.defaultValue.equals("0")) {
				for (nextParentCode = this.list.size(); nextParentCode > 0; --nextParentCode) {
					obj = (TreeObjectInterface) this.list
							.get(nextParentCode - 1);
					if (this.defaultValue.equals(obj.getObjectCode())) {
						defParentStr = obj.getObjectParentCodeStr();
						break;
					}
				}
			}

			for (nextParentCode = this.list.size(); nextParentCode > 0; --nextParentCode) {
				obj = (TreeObjectInterface) this.list.get(nextParentCode - 1);
				boolean currentLayerNum = false;
				if (this.justEnabled == 0) {
					currentLayerNum = true;
				} else if (this.justEnabled == 1) {
					if (obj.getEnabled().equals("Y")) {
						currentLayerNum = true;
					} else if (this.defaultValue != null
							&& this.defaultValue.equals(obj.getObjectCode())) {
						currentLayerNum = true;
					} else if (defParentStr != null
							&& defParentStr.indexOf(";" + obj.getObjectCode()
									+ ";") != -1) {
						currentLayerNum = true;
					}
				}

				if (currentLayerNum
						&& (obj.getObjectParentCode() == null
								|| obj.getObjectParentCode().equals("") || obj
								.getObjectParentCode().equals("0"))) {
					stack.push(obj);
					layerNumStack.push("1");
				}
			}

			while (true) {
				int arg15;
				do {
					if (stack.isEmpty()) {
						e.print(str);
						return 0;
					}

					obj = (TreeObjectInterface) stack.pop();
					arg15 = Integer.parseInt(((String) layerNumStack.pop())
							.toString());
				} while (this.exceptCode != null
						&& this.exceptCode.equals(obj.getObjectCode()));

				String tmpStr = "";
				if (arg15 > 1) {
					for (int selectStr = 0; selectStr < arg15 - 1; ++selectStr) {
						tmpStr = tmpStr + "&nbsp;";
					}

					tmpStr = tmpStr + "|--";
				}

				String arg16 = "";
				if (this.defaultValue != null
						&& this.defaultValue.equals(obj.getObjectCode())) {
					arg16 = " selected";
				}

				str = str + "\n";
				str = str + "<option value=\'" + obj.getObjectCode() + "\'"
						+ arg16 + ">" + tmpStr + obj.getObjectName()
						+ "</option>";
				String arg14 = obj.getObjectCode();

				for (int i = this.list.size(); i > 0; --i) {
					TreeObjectInterface tmpObj = (TreeObjectInterface) this.list
							.get(i - 1);
					boolean itemOk = false;
					if (this.justEnabled == 0) {
						itemOk = true;
					} else if (this.justEnabled == 1) {
						if (tmpObj.getEnabled().equals("Y")) {
							itemOk = true;
						} else if (this.defaultValue != null
								&& this.defaultValue.equals(tmpObj
										.getObjectCode())) {
							itemOk = true;
						} else if (defParentStr != null
								&& defParentStr.indexOf(";"
										+ tmpObj.getObjectCode() + ";") != -1) {
							itemOk = true;
						}
					}

					if (itemOk && tmpObj.getObjectParentCode().equals(arg14)) {
						stack.push(tmpObj);
						layerNumStack.push(String.valueOf(arg15 + 1));
					}
				}
			}
		} catch (Exception arg13) {
			throw new JspException(arg13.toString());
		}
	}

	public int doEndTag() {
		return 6;
	}

	public int getEmptyOption() {
		return this.emptyOption;
	}

	public void setEmptyOption(int emptyOption) {
		this.emptyOption = emptyOption;
	}

	public List getList() {
		return this.list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public String getExceptCode() {
		return this.exceptCode;
	}

	public void setExceptCode(String exceptCode) {
		this.exceptCode = exceptCode;
	}

	public String getDefaultValue() {
		return this.defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}
}